//
//  LBDianaFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 1/23/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBDianaFilter.h"

char dianaFilterFragStr[] = ""

"precision mediump float;"

"varying vec2 vtexCoor;"
"uniform sampler2D texture;"

//contrast function (default 1.0)
"vec4 contrastColor(vec4 color, float contrast){"
"   color.r = (color.r - 0.5)*contrast + 0.5;"
"   color.g = (color.g - 0.5)*contrast + 0.5;"
"   color.b = (color.b - 0.5)*contrast + 0.5;"
"   color = clamp(color, 0.0, 1.0);"
"   return color;"
"}"
//END contrast function

//function colorOffset
"vec4 colorOffset(vec4 color, vec4 offset){"
"   color = color + offset;"
"   return color;"
"}"
// END function colorOffset


// vignette function
"vec4 vignette(vec4 color, vec4 vignetteColor, vec2 center, highp float begin, highp float end, float intensity, vec2 texCoor){"
"   float d = distance(texCoor, vec2(center.x, center.y));"
"   float percent = smoothstep(begin, end, d) * intensity;"
"   vec4 result = vec4(mix(color.r, vignetteColor.x, percent), mix(color.y, vignetteColor.y, percent), mix(color.z, vignetteColor.z, percent), 1.0);"
"   return result;"
"}"
// END vignette function

"void main()"
"{"
"   lowp vec4 textureColor = texture2D(texture, vtexCoor);"
"   vec4 result = textureColor;"

"   result = contrastColor(result, 1.2);"
"   result = colorOffset(result, vec4(0.1, 0.05, 0.0, 0.0));"
"   result = vignette(result, vec4(0.227, 0.137, 0.086, 1.0), vec2(0.5, 0.5), 0.5, 0.9, 1.0, vtexCoor);"

"   gl_FragColor = result;"
"}";

LBDianaFilter::LBDianaFilter(){
    init(0, dianaFilterFragStr);
}